package com.shyb.lingxian.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by Administrator on 2018/3/22/022.
 */

public abstract class BaseFragment<P extends BasePresenter> extends Fragment {

    protected P presenter;
    protected abstract P initPresenter();
    protected abstract void initialize();


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = initView(inflater);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        presenter = initPresenter();
        initialize();
    }


    /**
     * 初始化view
     */
    public abstract View initView(LayoutInflater inflater);

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (presenter != null) presenter.dettachView();
    }
}
